$(document).ready(function(){
	
	$("#btn_buscar")
	.button({ icons: {primary:'ui-icon-search'} })
	.click(
		function(){
			Buscar();
		}
	);
	//Buscar();
	$( "#Tip_Estado" ).buttonset();
	$("input[name=rd_tipoestado]:radio").click(function(){Buscar();});
	//$("input[name='rd_tipoestado']").change(function(){Buscar();});
	$( "#btn_mante" )
			.button({icons : {primary:'ui-icon-document'}})
			.click(function() {
					VentanaPopUp(430,350,false,"Nuevo Proveedor",'Proveedor/mantenimiento?type=N',
						{
							Aceptar: function(){
								ExecActionMante('N')
								//$( this ).dialog( "close" );
							},
							Cancel: function() {
								$( this ).dialog( "close" );
							}
						}
					);
			});
				 
				 
});

function Buscar(){
	
	tip=$("#cboid_buscar").val();
	val=$("#txtds_buscar").val();
	chkval = $('input:radio[name=rd_tipoestado]:checked').val();
	
	$.ajax({
 		dataType: "html",
	 	type: "POST",
	 	url: jQuery.scriptPath +'index.php/Proveedor/buscar/',
	 	data: "tip="+tip+"&val="+val+"&chk="+chkval,
		beforeSend: function(data){	 	

		},
		success: function(requestData){ 	
			$("#div_result").html(requestData);
		},		
		error: function(requestData, strError, strTipoError){											
			$("#div_result").html("Error " + strTipoError +": " + strError);
		}
	});
}

function AbrirMenu(){
	
		$('#tbl_result tbody tr').contextMenu('MenuMante', {
		onContextMenu: function(e) {
	        $(e.target).parent().addClass('ui-state-active');
	        return true
		},
		onShowMenu: function(e, menu) {
        	return menu;
      },
      	bindings: {
        	'open': function(t) {
	          	VentanaPopUp(430,350,true,"Modificar Proveedor",'Proveedor/mantenimiento?type=M&codItem='+t.id,
						{
							Aceptar: function(){
								ExecActionMante('M')
								//$( this ).dialog( "close" );
							},
							Cancel: function() {
									$( this ).dialog( "close" );
							}
						}
					);
        	},
        	'delete': function(t) {
    	      	VentanaPopUp(430,350,true,"Eliminar Proveedor",'Proveedor/mantenimiento?type=E&codItem='+t.id,
						{
							Aceptar: function(){
								ExecActionMante('D')
								//$( this ).dialog( "close" );
							},
							Cancel: function() {
									$( this ).dialog( "close" );
							}
						}
					);
        	}
      	}
    });
    	$('#tbl_result tbody tr').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
}

